let Mock = require('mockjs');
const all = Mock.mock(
    {
        "tableData|58": [{   			//生成四个如下格式的数据
            "key|+1": 1, 						//数字从1开始，后续依次加1
            "name": "@cname",
            "email": "@county(true)",		//名字为随机中文名
            "age|18-28": 25, 			//年龄是18-28之间的随机数
            "website|1": ["男", "女"],	 //性别是数组里的随机一项
            "introduction|1": ["web", "teacher", "python", "php"]   //job是数组里的随机一项
        }]
    }
);
let data = Mock.mock('/table/list', 'post', (params:any) => {
    let info = JSON.parse(params.body)
    let [index, size, name, email, total] = [info.pageNo, info.pageSize, info.name, info.email, all.tableData.length]
    let newDataList = [...all.tableData];
    if(name){
        newDataList = newDataList.filter((e) => {
            return e.name.indexOf(name) !== -1;
        });
    }
    if(email){
        newDataList = newDataList.filter((e) => {
            return e.email.indexOf(email) !== -1;
        });
    }
    newDataList = newDataList.slice(index * size, (index + 1) * size);
    if(name || email) total = newDataList.length;
    let len:number = Number(total / size);
    let totalPages = len - len > 0 ? len+ 1 : len
    return {
        'code': '0',
        'message': 'success',
        'total': total,
        'totalPages': totalPages,
        'data': newDataList
    }
});
export default data;
